在學習演算法的過程中,我們時常遇到找不到符合自己程度的題目練習,導致大家不知道自己的實作能力,也不確定是否真正了解演算法理論,今年的 iThome 鐵人賽,我將開發一個實際能讓大家用的AI平台——AI LeetCode助教。
我們的目標很明確:幫助使用者透過生成式 AI 在 LeetCode 上更有效率地學習演算法,提供程度判斷、題目推薦、解題提示與錯誤分析,最終讓這個平台對所有程式學習者開放使用。
ai-leetcode-tutor/
├─ backend/ # FastAPI 後端
├─ frontend/ # Streamlit 前端
└─ README.md
前端:
pip install streamlit requests
後端:
pip install fastapi uvicorn[standard] pydantic SQLAlchemy python-dotenv
# backend/app.py
from fastapi import FastAPI
from .database import Base, engine
from .routers import problems
app = FastAPI(title="AI LeetCode Tutor API")
Base.metadata.create_all(bind=engine)
@app.get("/health")
def health():
return {"status": "ok"}
app.include_router(problems.router)
MOCK = [
{"slug":"two-sum","title":"Two Sum","difficulty":"Easy","topic":"Array"},
{"slug":"longest-substring","title":"Longest Substring Without Repeating Characters","difficulty":"Medium","topic":"HashMap"},
{"slug":"median-of-two-sorted-arrays","title":"Median of Two Sorted Arrays","difficulty":"Hard","topic":"Binary Search"}
]
# frontend/app.py
import streamlit as st
import requests
API_BASE = "http://127.0.0.1:8000"
st.title("AI LeetCode 助教(Day 1 雛形)")
st.subheader("系統狀態")
st.write(requests.get(f"{API_BASE}/health").json())
st.subheader("題目列表")
for p in requests.get(f"{API_BASE}/problems").json():
st.write(f"[{p['difficulty']}] {p['title']} ({p['topic']})")
cd backend
uvicorn app:app --reload
python seed_mock.py
cd frontend
streamlit run app.py
第一天介紹了這個專案動機以及目標,並且完成了整個專案的基礎架構,雖然功能很簡單,但今天已經實作出: